package com.mx.zb.mng.ctrl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.mx.zb.mng.bo.Agent;
import com.mx.zb.mng.bo.Tenant;
import com.mx.zb.mng.dao.AgentMapper;
import com.mx.zb.mng.dao.TenantMapper;
import com.mx.zb.mng.utils.AjaxResult;

@RestController
@RequestMapping("/i/tenant")
public class ITenantCtrl {

	@Autowired
	TenantMapper tenantMapper;
	@Autowired
	AgentMapper agentMapper;

	@RequestMapping(value = { "/update/updateTenant" }, method = { RequestMethod.POST })
	public void updateTenant(@RequestBody JSONObject params) {
		Tenant ta = params.getObject("tenant", Tenant.class);
		if (null != ta) {
			Tenant te = new Tenant();
			te.setId(ta.getId());
			te.setName(ta.getName());
			te.setAddress(ta.getAddress());
			te.setPhone(ta.getPhone());
			te.setProvince(ta.getProvince());
			te.setCity(ta.getCity());
			tenantMapper.updateByPrimaryKeySelective(te);
		}
	}
	
	
	@RequestMapping(value = { "/getAgentInfo" }, method = { RequestMethod.POST })
	public AjaxResult readerNote(@RequestBody JSONObject params) {
		String id = params.getString("id");// 获取店铺id
		Tenant tenant =tenantMapper.selectByPrimaryKey(id);
		Agent agent=new Agent();
		if(tenant!=null) {
			 agent=agentMapper.selectByPrimaryKey(tenant.getAgentId());
		}
		return new AjaxResult().success(agent.getPhone());
	}

}
